package com.kaifamiao.schema;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.Method;

public class PandaAroundAdvice implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation mi) throws Throwable {
        final Method m = mi.getMethod();
        Object target = mi.getThis(); // 获得代理目标
        Object[] args = mi.getArguments(); // 获得实参
        System.out.println( "开始计时" );
        long start = System.nanoTime();
        // Object result = mi.proceed(); // 执行目标方法
        Object result = m.invoke( target , args );
        long end = System.nanoTime();
        System.out.println( "计时结束" );
        System.out.println( "【" + m.getName() + "】方法执行耗时" + (end-start) + "ns." );
        return result;
    }

}
